package com.zgy.backend.bookstore.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Author: renjiaxin
 * @Despcription: 解决跨域问题
 * Access to XMLHttpRequest at 'http://localhost:8991/book/all' from origin 'http://localhost:8080' has been blocked by
 * CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
 * @Date: Created in 2020/7/21 2:54
 * @Modified by:
 */
@Configuration
public class CrosConfig implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("*")
                .allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS")
                .allowCredentials(true)
                .maxAge(3600)
                .allowedHeaders("*");
    }
}